package com.ruoyi.service.project.enums;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import lombok.Getter;

/**
 * <p>
 * 作用：区域等级
 * </p>
 *
 * @author Zane
 * @since 2025-10-05 21:15
 */
@Getter
public enum ProjectStatusEnum {
  // 0 未发布、1 筹备中、2 执行中、3 执行完毕交付中、4 交付完毕验收中、5 验收完毕结算中、6 结算完成,默认0
  CREATE(0, "未发布", "项目保存完成，未发布"),
  PUBLISH(1, "筹备中", "项目已发布且项目周期未开始"),
  ON_EXECUTION(2, "执行中", "项目周期开始时间已到"),
  ON_DELIVERY(3, "交付中", "全员项目打卡完成且项目报告未完毕"),
  VERIFYING(4, "验收中", "制作方已交付，项目方未验收"),
  SETTLING(5, "结算中", "项目成验收完成，薪酬扣点未发放"),
  SETTLED(6, "结算完成", "薪酬扣点已发放");
  /**
   * 编码
   */
  private final int code;
  /**
   * 状态名称
   */
  private final String name;
  /**
   * 描述
   */
  private final String desc;

  ProjectStatusEnum(int code, String name, String desc) {
    this.code = code;
    this.name = name;
    this.desc = desc;
  }


  public boolean eqCode(int code) {
    return this.code == code;
  }

  public static boolean couldEdit(int code) {
    return CREATE.eqCode(code)
        || PUBLISH.eqCode(code)
        || ON_EXECUTION.eqCode(code)
        || ON_DELIVERY.eqCode(code);
  }

  /**
   * 已启动,待交付状态
   */
  public static boolean startButNotFinish(int code) {
    return ON_EXECUTION.eqCode(code)
        || ON_DELIVERY.eqCode(code);
  }

  public static boolean hasPublished(Integer status) {
    return Optional.ofNullable(status).orElse(0) > CREATE.code;
  }

  public static boolean couldRate(int code) {
    return SETTLING.eqCode(code) || SETTLED.eqCode(code);
  }

  //用于延期通知
  private static final List<Integer> notifyStatus = Arrays.asList(ON_EXECUTION.getCode(),
      ON_DELIVERY.getCode());

  public static List<Integer> getNotifyStatusList() {
    return notifyStatus;
  }

  //用于可以开发票状态
  private static final List<Integer> settleStatus = Arrays.asList(SETTLING.getCode(),
      SETTLED.getCode());

  public static List<Integer> getSettleStatusList() {
    return settleStatus;
  }

  public static boolean couldInvoice(int code) {
    return SETTLING.eqCode(code)
        || SETTLED.eqCode(code);
  }

}
